<?php

class Database {
   
   private $user;

   private $password;

   private $host = "127.0.0.1";

   private $port = 3306;

   private $database;

   private $connected = false;

   private $link;

   public function connect() {

      $this->link = 
         mysql_connect($this->host . ":" . $this->port, $this->user, $this->password);

      if ($this->link) {
		 mysql_set_charset('utf8', $this->link);

         if (mysql_select_db($this->database)) {

            $this->connected = true;
         }
      }

      return $this->connected;
         
   }
   public function disconnect() {

      if ($this->connected) {

         mysql_close($this->link);
         $this->connected = false;

      }
   }

   public function query($sql) {

      $result = null;

      if ($this->connected) {
         $result = mysql_query($sql, $this->link);

         if (!$result)
            $result = null;
      }

      return $result;

   }

   public function insert($sql) {
      return mysql_query($sql, $this->link);
   }

   public function update($sql) {
      return mysql_query($sql, $this->link);
   }

   public function delete($sql) {
      return mysql_query($sql, $this->link);
   }

   // getters and setters

   public function isConnected() {
      return $this->connected;
   }

   public function setUser($user) {
      $this->user = $user;
   }

   public function getUser() {
      return $this->user;
   }

   public function setPassword($password) {
      $this->password = $password;
   }

   public function getPassword($password) {
      return $this->password;
   }

   public function setHost($host) {
      return $this->host;
   }

   public function getHost() {
      return $this->host;
   }

   public function setPort($port) {
      $this->port = $port;
   }

   public function getPort() {
      return $this->port;
   }

   public function setDatabase($database) {
      $this->database = $database;
   }

   public function getDatabase() {
      return $this->database;
   }
}

?>
